﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Collaboris Ltd." file="ActionReport.cs">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   Contains information about the execution
//   of a single Action.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.Saf.Engine.Report
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Xml.Serialization;

    using Utils;

    /// <summary>
    /// Contains information about the execution
    /// of a single Action.
    /// </summary>
    [Serializable]
    public class ActionReport : ReportBase<EntityReport>
    {
        private SerializableObjectDictionary<string> contextProperties;

        /// <summary>
        /// Stores the index of the action in the macro
        /// </summary>
        private int actionIndex;

        /// <summary>
        /// Process status.
        /// </summary>
        private ProcessStatus status;

        /// <summary>
        /// Contains the most "severe" status of 
        /// any Action within the macroReport.
        /// </summary>
        /// <remarks>
        /// The Potential Status (most severe first are :)
        /// <see cref="ProcessStatus"/>.Stop
        /// <see cref="ProcessStatus"/>.Error
        /// <see cref="ProcessStatus"/>.Success
        /// </remarks>
        [XmlIgnore]
        public override ProcessStatus Status
        {
            get
            {
                if (this.EntityReports.Count > 0)
                {
                    foreach (IProgressReport report in this.EntityReports)
                    {
                        this.status = this.DetermineWorstCase(this.status, report.Status);
                    }
                }
                else
                {
                    return this.status;
                }

                return this.status;
            }

            set
            {
                this.status = value;
            }
        }

        /// <summary>
        /// Gets or sets EntityReports.
        /// </summary>
        [XmlElement]
        public List<EntityReport> EntityReports
        {
            get
            {
                if (this.reportList == null)
                {
                    this.reportList = new List<EntityReport>();
                }

                return this.reportList;
            }

            set
            {
                this.reportList = value;
            }
        }

        /// <summary>
        /// Represents the Properties stored and maintained
        /// in the <see cref="SafContext"/>.
        /// </summary>
        public SerializableObjectDictionary<string> ContextProperties
        {
            get
            {
                return this.contextProperties;
            }

            set
            {
                this.contextProperties = value;
            }
        }

        /// <summary>
        /// Gets or sets the index of the action in the macro.
        /// </summary>
        /// <value>The index of the action.</value>
        public int ActionIndex
        {
            get
            {
                return this.actionIndex;
            }
            set
            {
                this.actionIndex = value;
            }
        }
    }
}